
function saveUserInfo(lUserInfo) {
  //	private String username;
  // private String privatekey;//私钥
  // wx.setStorage({
  //   key: "userHead",
  //   data: lUserInfo.img
  // })
  // wx.setStorage( {
  //     key: "username",
  //     data: lUserInfo.username
  //   })
  // wx.setStorage({
  //     key: "privatekey",
  //     data: lUserInfo.privatekey
  //   })
}
function returnLastPage() {//返回上一页面
  wx.navigateBack({
    delta: 1
  })
}
function returnLastTwoPage(i) {//返回上某个页面
  wx.navigateBack({
    delta: i
  })
}
function closeCurrPage(url) {//关闭当前页面  并打开新的页面
  wx.redirectTo({
    //目的页面地址
    url: url
  })
}
function openNewPage(url) {//保留当前页面  并打开新的页面
  wx.navigateTo({
    //目的页面地址
    url: url
  })
}
function log(log) {//打印log
  console.log(log)
}
function isContains(str, substr) {
  return str.indexOf(substr) >= 0;
}
function getCardText(CardType) {
  // <!--身份证 = 0, 护照 = 1, 港澳通行证 = 2, 台胞证 = 3, 台湾通行证 = 4, 回乡证 = 5, 军官证 = 6, 其他 = 10]  -->
  var cardText = null;
  switch (CardType) {
    case 0:
      cardText = "身份证";
      break;
    case 1:
      cardText = "护照";
      break;
    case 2:
      cardText = "港澳通行证";
      break;
    case 3:
      cardText = "台胞证";
      break;
    case 4:
      cardText = "台湾通行证";
      break;
    case 5:
      cardText = "回乡证";
      break;
    case 6:
      cardText = "军官证";
      break;
    case 10:
      cardText = "其他";
      break;
  }
  return cardText;
}
function getAgeBybirth(str) {//格式 2002-01-41
  var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
  if (r == null) return false;
  var d = new Date(r[1], r[3] - 1, r[4]);
  if (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]) {
    var Y = new Date().getFullYear();
    return (Y - r[1]);
  }
  return ("输入的日期格式错误！");
}   
function arrayContain(array, str) {
  for (var i = 0; i < array.length; i++) {
    if (array[i] == str) {
      return true;
    }
  }
}
module.exports = {
  saveUserInfo: saveUserInfo,
  closeCurrPage: closeCurrPage,
  openNewPage: openNewPage,
  returnLastPage: returnLastPage,
  log: log,
  isContains: isContains,
  returnLastTwoPage: returnLastTwoPage,
  getCardText: getCardText,
  getAgeBybirth: getAgeBybirth,
  arrayContain: arrayContain,
}